#include <dbg.h>

#include <cassert>

using namespace std;

class Solution {
public:
    int numOfSubarrays(vector<int>& arr, int k, int threshold) {
        int res = 0;
        int sum = 0;  // 窗口和
        for (int i = 0; i < arr.size(); ++i) {
            sum += arr[i];
            if (i < k - 1) {  // 窗口还没满
                continue;
            }
            res += sum >= k * threshold;  // 窗口满了，判断是否满足条件
            sum -= arr[i - k + 1];        // 窗口满了，减去最左边的数
        }
        return res;
    }
};

int main() {
    Solution s;

    vector<int> arr1 = {2, 2, 2, 2, 5, 5, 5, 8};
    vector<int> arr2 = {11, 13, 17, 23, 29, 31, 7, 5, 2, 3};

    int k1 = 3;
    int k2 = 3;

    int threshold1 = 4;
    int threshold2 = 5;

    assert(s.numOfSubarrays(arr1, k1, threshold1) == 3);
    assert(s.numOfSubarrays(arr2, k2, threshold2) == 6);

    return 0;
}